package com.example.shixunandjavagotoyangchen.BoosYang.Day003;

import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.modelviewpresenter.View.BasterFragment;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00102.SmileDay00102Adpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00102.SmileDay00102Bean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1101.NingserDay002_1101Adpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1101.NingserDay002_1101Bean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day003.Day003_FX1.FaxianDay003FX1_Adpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day003.Day003_FX1.FaxianDay003FX1_Bean;
import com.example.shixunandjavagotoyangchen.R;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import java.util.List;

public class BlankFragmentDay003_FX1 extends BasterFragment {


    private RecyclerView Faxian1RecyclerView;
    public int fcont=0;
    FaxianDay003FX1_Adpter adpter;
    boolean isfaxian = true;
    @Override
    public int BandLayout() {
        return R.layout.fragment_blank_fragment_day003__fx1;
    }

    @Override
    public void initView() {

        Faxian1RecyclerView = (RecyclerView) findViewById(R.id.Faxian1_RecyclerView);
        Faxian1RecyclerView.setLayoutManager(new StaggeredGridLayoutManager(1,StaggeredGridLayoutManager.VERTICAL));
    }

    @Override
    public void initDate() {

        OkGo.<String>get("http://82.156.173.100:8087//video/findVideos?currentPage=26&pageSize=30").execute(new StringCallback() {
            @Override
            public void onSuccess(Response<String> response) {
                Gson gson = new Gson();
                FaxianDay003FX1_Bean faxianDay003FX1_bean = gson.fromJson(response.body().toString(), FaxianDay003FX1_Bean.class);
                List<FaxianDay003FX1_Bean.DataBean> shujuBeans = faxianDay003FX1_bean.getData();
                for (FaxianDay003FX1_Bean.DataBean dataBean : shujuBeans) {
                    dataBean.setFaxianLayout(++fcont);
                    if (fcont==4){
                        fcont=0;
                    }
                }
                if (adpter==null){
                    adpter = new FaxianDay003FX1_Adpter(shujuBeans);
                    Faxian1RecyclerView.setAdapter(adpter);
                }else {
                    if (isfaxian){
                        adpter.getData().clear();
                    }
                    adpter.getData().addAll(shujuBeans);
                    adpter.notifyDataSetChanged();
                }


            }
        });



    }
}
